/**
 * 获取字典值
 */
function getDictText(code, value) {
    let dictStr = localStorage.getItem("dict");

    if(dictStr === undefined) {
        top.$.messager.show({
            title: 'Error',
            msg: '字典初始化错误，请刷新页面！'
        });
        return;
    }

    let dictMap = $.parseJSON(dictStr);

    if(dictMap[code] === undefined) {
        return null;
    }

    let dict = dictMap[code];
    for(let i = 0; i < dict.length; i++)
    {
        if(value === dict[i].value) {
            return dict[i].text;
        }
    }
}

/**
 * 初始化字典
 */
function initDict() {

    $.ajax({
        url: "/dict/findAllDict",
        type: "POST",
        contentType: "application/json",
        dataType: "json",
        success: function(result) {
            if (result.success){
                localStorage.removeItem("dict");
                localStorage.setItem("dict", JSON.stringify(result.data));
                console.log('字典初始化成功', result.data);
            } else {
                top.$.messager.show({
                    title: 'Error',
                    msg: '字典初始化失败，请刷新页面'
                });

                console.log(result);
            }
        }
    });
}


//扩展jquery的格式化方法
$.fn.parseForm=function(){
    var serializeObj={};
    var array=this.serializeArray();
    var str=this.serialize();
    $(array).each(function(){
        if(serializeObj[this.name]){
            if($.isArray(serializeObj[this.name])){
                serializeObj[this.name].push(this.value);
            }else{
                serializeObj[this.name]=[serializeObj[this.name],this.value];
            }
        }else{
            serializeObj[this.name]=this.value;
        }
    });
    return serializeObj;
};